<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>购物车</title>
		<link rel="stylesheet" type="text/css" href="./Public/Home/css/shopcar.css"/>
		<script src="./Public/Home/js/jquery-1.7.2.min.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		{{include file="../Common/header"}}
		<!--购物车标题-->
		<div id="car_title">
			<h2></h2>
		</div>
		<!--购物车内物品-->
		<div id="main_car">
			<div class="main_car_center">
				<!--物品栏-->
				<ul class="buy_list">
					{{if value="isset($allData)"}}
					{{foreach from="$allData['goods']" $key="$k" value="$u"}}
					<input type="hidden" class="hidded{{$k}}" value="{{$k}}">
					<li class="clear">
						<a href="{{U('Detail/index',['coid'=>$u['id']])}}" class="good_img_box">
							<img src="{{$u['commodimg']}}" alt="" />
						</a>
						<div class="goods_info">
							<div class="goods_titbox">
								<p class="goods_titletext">{{$u['name']}}</p>
								<a href="javascript:if(confirm('确定删除吗？')) location.href='{{U('delCommod',['commodid'=>$k])}}';" class="goods_del">删除</a>
							</div>
							<div class="goods_infobox1">
								<p class="cgoods_info1">
									{{foreach from="$u['options']" value="$v"}}
									<span>{{$v}}</span>
									{{endforeach}}
								</p>
								<p class="cgoods_price">价格:￥<span>{{$u['price']}}</span></p>
							</div>
							<div class="goods_buynum">
								<p class="title">数量：</p>
								<div class="buy_counter">
									<a href="javascript:;" class="rduce{{$k}} btn">-</a>
									<input type="text" class="result" readonly="readonly" name="result" id="" value="{{$u['num']}}" />
									<a href="javascript:;" class="add{{$k}} btn">+</a>
								</div>
								<!--购物车加减数量-->
								<script type="text/javascript">
									$(function(){
										$(".add{{$k}}").click(function(){
//											var a=$(".sales .kc_num").html();
//														alert(a);
											var n=$(this).prev().val();
											var num=parseInt(n)+1;
//											if(num>a){alert('不能选择超出库存的数量哦');return;}
											if(num==0){ return;}
											$(this).prev().val(num);
											var commodid=$('.hidded{{$k}}').val();
//											alert(commodid);
											$.ajax({
												type:"post",
												url:"{{U('Shopcar/editCommon')}}",
												data:{num:num,commodid:commodid},
												//指定服务器返回的数据类型
												dataType:'json',
												success:function(phpData){
													console.log(phpData);
//													异步之后所有商品总价
													var str='';
													str+='￥'+'<i>'+phpData.totalPrice+'</i>';
													var attr='';
													attr+='<b>'+phpData.TotalNums+'</b>';
													var attrp='';
													attrp+='<b>'+phpData.TotalNums+'</b>';
													var goodPri='';
													goodPri+='￥'+'<i>'+{{$u['price']}}*phpData.num+'</i>';
													$('.num2').html(str);
													$('.num3').html(attr);
													$('.num4').html(attr);
													$('.silder').html(attrp);
													$('.price{{$k}}').html(goodPri);
											}
										})
									})
									$(".rduce{{$k}}").click(function(){
										var n=$(this).next().val();
										var num=parseInt(n)-1;
										if(num==0){alert('最少购买一件商品哦(:');return;}
										$(this).next().val(num);
										var commodid=$('.hidded{{$k}}').val();
										$.ajax({
											type:"post",
											url:"{{U('Shopcar/editCommon')}}",
											data:{num:num,commodid:commodid},
											//指定服务器返回的数据类型
											dataType:'json',
											success:function(phpData){
//											console.log(phpData);
//													异步之后所有商品总价
											var str='';
											str+='￥'+'<i>'+phpData.totalPrice+'</i>';
											var attr='';
											attr+='<b>'+phpData.TotalNums+'</b>';
											var attrp='';
											attrp+='<b>'+phpData.TotalNums+'</b>';
											var goodPri='';
											goodPri+='￥'+'<i>'+{{$u['price']}}*phpData.num+'</i>';
											$('.num2').html(str);
											$('.num3').html(attr);
											$('.num4').html(attr);
											$('.silder').html(attrp);
											$('.price{{$k}}').html(goodPri);
											}
									})
								});
							})
							</script>
							</div>
							<div class="goods_infobox2">
								<p class="goods_sum">小计：<span  class="price{{$k}}">￥<i>{{$u['total']}}</i></span></p>
							</div>
						</div>
					</li>
					{{endforeach}}
					{{else}}
					<p>购物车内没有物品，请去挑选吧！</p>
					{{endif}}
				</ul>
				<!--下方统计信息栏-->
				<p class="buy_tips">当前购物车中共有
					<span class="num num4">{{if value="isset($allNum)"}}{{$allNum}}{{else}}0{{endif}}</span>件商品，目前已选中
					<span class="num num4">{{if value="isset($allNum)"}}{{$allNum}}{{else}}0{{endif}}</span>件商品，请确认购物车里的商品并结算。
					<a href="{{U('Index/index')}}" class="btn">继续购物</a>
				</p>
				<!--结算框-->
				<div class="settlement">
					<div class="settle_box">
						<div class="buy_price">
							<p class="freight">运费：<span class="num">￥ 0.00</span></p>
							<p class="set_info">
								<span class="item">共<span class="num3"><i>{{if value="isset($allNum)"}}{{$allNum}}{{else}}0{{endif}}</i></span>件商品</span>
								<span class="item">实付：
									<span class="num2">
									￥<i>{{if value="isset($allpri)"}}{{$allpri}}{{else}}0{{endif}}</i>
									</span>
								</span>
							</p>
						</div>						
						<a href="{{U('Order/index')}}" class="buy_btn1">去结算</a>
					</div>					
				</div>
			</div>
		</div>
		<!--底部区域-->
		{{include file="../Common/footer"}}
		<!--底部区域-->
	</body>
</html>
